from time import sleep
from tb_device_mqtt import TBDeviceMqttClient


# dependently of request method we send different data back
def on_server_side_rpc_request(request_id, request_body):
    print(request_id, request_body)
    if request_body["method"] == "getCPULoad":
        client.send_rpc_reply(request_id, {"CPU percent"})
    elif request_body["method"] == "getMemoryUsage":
        client.send_rpc_reply(request_id, {"Memory"})
    else:
        client.send_rpc_reply(request_id, {"error": "unknown method"})


token1 = "yygk42lgziaz74uobzlk"
token2 = "49pazwksi1xb1tdeg8ao"
# global client
client = TBDeviceMqttClient("127.0.0.1", 1883, username=token2)
client.set_server_side_rpc_request_handler(on_server_side_rpc_request)
client.connect()

while True:
    sleep(1)
